﻿using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using com.gexin.rp.sdk.dto;
using com.igetui.api.openservice.igetui;

namespace com.igetui.api.openservice
{
	// Token: 0x02000023 RID: 35
	public class BatchImpl : IBatch
	{
		// Token: 0x06000453 RID: 1107 RVA: 0x000094D4 File Offset: 0x000076D4
		public BatchImpl(string appKey, IGtPush push)
		{
			this.batchId = Guid.NewGuid().ToString();
			this.APPKEY = appKey;
			this.push = push;
		}

		// Token: 0x06000454 RID: 1108 RVA: 0x000020A2 File Offset: 0x000002A2
		public void setApiUrl(string url)
		{
		}

		// Token: 0x06000455 RID: 1109 RVA: 0x00009519 File Offset: 0x00007719
		public string getBatchId()
		{
			return this.batchId;
		}

		// Token: 0x06000456 RID: 1110 RVA: 0x00009524 File Offset: 0x00007724
		public string add(SingleMessage message, com.igetui.api.openservice.igetui.Target target)
		{
			if (this.seqId >= 5000)
			{
				throw new Exception("Can not add over 5000 message once! Please call submit() first.");
			}
			string data = this.createPostParams(message, target);
			SingleBatchItem item = SingleBatchItem.CreateBuilder().SetSeqId(this.seqId).SetData(data).Build();
			this.innerMsgList.Add(item);
			this.seqId++;
			return string.Concat(this.seqId);
		}

		// Token: 0x06000457 RID: 1111 RVA: 0x00009598 File Offset: 0x00007798
		public string createPostParams(SingleMessage message, com.igetui.api.openservice.igetui.Target target)
		{
			Dictionary<string, object> dictionary = new Dictionary<string, object>();
			dictionary.Add("action", "pushMessageToSingleAction");
			dictionary.Add("appkey", this.APPKEY);
			dictionary.Add("clientData", Convert.ToBase64String(message.Data.getTransparent().ToByteArray()));
			dictionary.Add("transmissionContent", message.Data.getTransmissionContent());
			dictionary.Add("isOffline", message.IsOffline);
			dictionary.Add("offlineExpireTime", message.OfflineExpireTime);
			dictionary.Add("appId", target.appId);
			dictionary.Add("clientId", target.clientId);
			dictionary.Add("type", 2);
			dictionary.Add("pushType", message.Data.getPushType());
			dictionary.Add("version", "3.0.0.0");
			return new JavaScriptSerializer().Serialize(dictionary);
		}

		// Token: 0x06000458 RID: 1112 RVA: 0x00009694 File Offset: 0x00007894
		public string submit()
		{
			string value = Guid.NewGuid().ToString();
			this.seqId = 0;
			Dictionary<string, object> dictionary = new Dictionary<string, object>();
			dictionary.Add("requestId", value);
			dictionary.Add("appkey", this.APPKEY);
			dictionary.Add("action", "pushMessageToSingleBatchAction");
			dictionary.Add("serialize", "pb");
			dictionary.Add("async", GtConfig.isPushSingleBatchAsync());
			SingleBatchRequest singleBatchRequest = SingleBatchRequest.CreateBuilder().SetBatchId(this.batchId).AddRangeBatchItem(this.innerMsgList).Build();
			dictionary.Add("singleDatas", Convert.ToBase64String(singleBatchRequest.ToByteArray()));
			this.lastPostData = dictionary;
			this.innerMsgList.Clear();
			return this.push.httpPostJSON(this.push.host, dictionary, true);
		}

		// Token: 0x06000459 RID: 1113 RVA: 0x00009775 File Offset: 0x00007975
		public string retry()
		{
			if (this.lastPostData != null)
			{
				return this.push.httpPostJSON(this.push.host, this.lastPostData, true);
			}
			return null;
		}

		// Token: 0x040002AA RID: 682
		private string batchId;

		// Token: 0x040002AB RID: 683
		private List<SingleBatchItem> innerMsgList = new List<SingleBatchItem>();

		// Token: 0x040002AC RID: 684
		private int seqId;

		// Token: 0x040002AD RID: 685
		private string APPKEY;

		// Token: 0x040002AE RID: 686
		private IGtPush push;

		// Token: 0x040002AF RID: 687
		private Dictionary<string, object> lastPostData;
	}
}
